package com.zly.Test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.junit.Test;

import com.zly.entity.One;
import com.zly.entity.User;
import com.zly.service.DormService;
import com.zly.service.impl.DormServiceImpl;

public class TestHibernate {

	/*public static void main(String[] args) {
		// 加载hibernate的核心配置文件
		Configuration configuration = new Configuration().configure();
		// 获取sessionFactory
		SessionFactory sessionFactory = configuration.buildSessionFactory();
		// 获取session
		Session session = sessionFactory.openSession();
		// 关闭连接
		session.close();
	}*/
	/**
	 * 增加数据
	 */
	@Test
	public void test() {
		DormService<One> dormService = new DormServiceImpl<>();
		One one = new One(0,"zly","男");
		One one2 = new One(0,"zly","女");
		dormService.save(one);
		dormService.save(one2);
	}
	/**
	 * 更新数据
	 */
	@Test
	public void update() {
		DormService<One> dormService = new DormServiceImpl<>();
		One one = new One(8,"zly","女");
		dormService.update(one);;
	}
	/**
	 * 删除数据
	 */
	@Test
	public void delete() {
		DormService<One> dormService = new DormServiceImpl<>();
		One one = new One(9,"1","2");
//		dormService.delete(one);
		dormService.deleteById(One.class, 5);
	}
}
